package com.reliable.api.dto.excel;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;

import java.util.Date;

/**
 * IP信息导出Excel DTO
 */
@Data
@HeadRowHeight(20)
@ContentRowHeight(18)
public class XssIpExcel {

    @ExcelProperty("IP地址")
    @ColumnWidth(20)
    private String ip;

    @ExcelProperty("IP归属地")
    @ColumnWidth(25)
    private String ipLocation;

    @ExcelProperty("ISP供应商")
    @ColumnWidth(20)
    private String isp;

    @ExcelProperty("是否代理/VPN")
    @ColumnWidth(15)
    private String proxy;

    @ExcelProperty("关联任务数")
    @ColumnWidth(12)
    private Integer taskCount;

    @ExcelProperty("关联终端数")
    @ColumnWidth(12)
    private Integer terminalCount;

    @ExcelProperty("总访问次数")
    @ColumnWidth(12)
    private Integer visitCount;

    @ExcelProperty("首次发现时间")
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    @ColumnWidth(20)
    private Date firstSeen;

    @ExcelProperty("最后发现时间")
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    @ColumnWidth(20)
    private Date lastSeen;

    @ExcelProperty("历史任务")
    @ColumnWidth(40)
    private String historicalTasks;

    @ExcelProperty("封IP标志")
    @ColumnWidth(12)
    private String banIpFlag;

    @ExcelProperty("国家代码")
    @ColumnWidth(12)
    private String countryCode;

    /**
     * 获取封禁状态的中文显示
     * @return
     */
    public String getBanIpFlag() {
        if (this.banIpFlag == null) {
            return "";
        }
        // 根据业务逻辑，1表示封禁中，其他值表示未封禁或其他状态
        try {
            Integer flag = Integer.valueOf(this.banIpFlag);
            return flag == 1 ? "封禁中" : "未封禁";
        } catch (NumberFormatException e) {
            return this.banIpFlag;
        }
    }
}
